import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import mongoose, { HydratedDocument } from 'mongoose';
import { ChatMessageTypes, ChatRolesTypes } from './chat.dto';

export type MessageDocument = HydratedDocument<Message>;

// message.schema.ts
@Schema({ timestamps: true })
export class Message {
  @Prop({ required: true })
  sender_type: ChatRolesTypes;

  @Prop({ required: true })
  sender_id: number;

  @Prop({ required: true })
  receiver_type: ChatRolesTypes;

  @Prop({ required: true })
  receiver_id: number;

  @Prop({
    type: String,
    enum: ChatMessageTypes,
    required: true,
  })
  message_type: string;

  @Prop({ type: mongoose.Schema.Types.Mixed })
  content: any; // 存储不同类型内容
}

export const MessageSchema = SchemaFactory.createForClass(Message);
